<%@page import="bean.Medicament"%>
<%@page import="java.util.ArrayList"%>
<%@page import="form.Valider"%>
<%@page import="bean.Patient"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<jsp:useBean id="patient" scope="request" class="bean.Patient" />

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<SCRIPT LANGUAGE="JavaScript">

	function Ajouter(form) {
		var o=new Option(form.libelle.value +" - "+ form.posologie.value,form.posologie.value);
		form.liste.options[form.liste.options.length]=o;
	}
	
	function Supprimer(list) {
		if (list.options.selectedIndex>=0) {
			list.options[list.options.selectedIndex]=null;
		} else {
			alert("Suppression impossible : aucune ligne sélectionnée");
		}
	}

	function SupprimerTout(list) {
		list.options.length=0;
	}
</SCRIPT>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Creer une nouvelle ordonnance</title>
<style type="text/css">

/* Autocomplete: */
.autocomplete-w1 { background:url(img/shadow.png) no-repeat bottom right; position:absolute; top:0px; left:0px; margin:8px 0 0 6px; /* IE6 fix: */ _background:none; _margin:0; }
.autocomplete { border:1px solid #999; background:#FFF; cursor:default; text-align:left; max-height:350px; overflow:auto; margin:-6px 6px 6px -6px; /* IE6 specific: */ _height:350px;  _margin:0; _overflow-x:hidden; }
.autocomplete .selected { background:#F0F0F0; }
.autocomplete div { padding:2px 5px; white-space:nowrap; }
.autocomplete strong { font-weight:normal; color:#3399FF; }
</style>

</head>
<script type="text/javascript" src="../jQuerry/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../jQuerry/jquery.autocomplete.js"></script>
<body>
<%@ include file="../commun_page_swmenufree/swmenufree.jsp" %>
<jsp:include page="${pageConfig.contenu}" />
<%
	
%>
<h3>Creation d'une nouvelle ordonnance</h3>
<form name="search" method="post">
	<table>
	<tr>
		<td>Rechercher un patient : </td>
		<td><input type="text" name="inputNom" size=20 maxlength=255 id="query" /></td>
		<td>${patient.err.nom}</td>
	</tr>	
	</table>
</form>
<FORM name="medoc">
	Nom medicament : <INPUT type="text" name="libelle" size=50 maxlength=255 value="" id="medoc"> 
	<br> Posologie : <INPUT type="text" name="posologie" size=100 maxlength=255 value=""> 
	<INPUT type="button" Value="Ajouter" onClick="Ajouter(this.form)"> 
	<BR><BR>
	Liste des medicaments prescrits : <br>
	<SELECT align=top name="liste" size=3 >
	</SELECT><br>
		<INPUT type="button" value="Supprimer la sélection" onClick="Supprimer(this.form.liste)">
		<INPUT type="button" value="Supprimer tout" onClick="SupprimerTout(this.form.liste)">
</FORM>

<script type="text/javascript">
  //<![CDATA[
   var a = $('#query').autocomplete({ 
    minChars:2, 
    delimiter: /(,|;)\s*/, // regex or character
    lookup: [<% ArrayList<Patient> tabPatient = new ArrayList<Patient>();
				tabPatient = Patient.listePatient();
				int i=0;
				for (Patient patient2 : tabPatient) {
					out.print("'");
					out.print(""+patient2.getNom()+" "+patient2.getPrenom());
					out.print("'");
					i++;
					if(i<tabPatient.size()) {
						out.print(",");
					}
				}
				
             %>] //local lookup values 
  });
   
   var a1 = $('#medoc').autocomplete({ 
    onSelect: function(value, data){
    	//alert('You selected: ' + value);
    	var MonTableau = new Array();
    	<% ArrayList<Medicament> tabMedoc2 = new ArrayList<Medicament>();
		tabMedoc2 = Medicament.listeMedoc();
		for (Medicament medoc2 : tabMedoc2) {
			out.print("MonTableau[\"");
			out.print(""+medoc2.getNom());
			out.println("\"] = \""+medoc2.getPosologie()+"\";");
		}
    	%>
    	document.getElementById("posologie").value = MonTableau[value];
    },
    minChars:2, 
    delimiter: /(,|;)\s*/, // regex or character
    lookup: [<% ArrayList<Medicament> tabMedoc = new ArrayList<Medicament>();
    			tabMedoc = Medicament.listeMedoc();
				int i1=0;
				for (Medicament medoc : tabMedoc) {
					out.print("'");
					out.print(""+medoc.getNom());
					out.print("'");
					i1++;
					if(i1<tabMedoc.size()) {
						out.print(",");
					}
				}
				
             %>] //local lookup values 
  });
//]]>

</script>

</body>
</html>